import cv2
import numpy as np

img = cv2.imread("img/salt_pepper_noise_example2.png")

# 当正则华为True时，等效于均值滤波；当正则为Fale,
normalize = False
a = 9
if not normalize:
    a = 1
# 定义卷积核
kernel = np.array([
    [1 / a, 1 / a, 1 / a],
    [1 / a, 1 / a, 1 / a],
    [1 / a, 1 / a, 1 / a]
])

result = cv2.filter2D(img, -1, kernel)
cv2.imshow("result", result)
cv2.waitKey(0)
